//
//  MovieLyrics.m
//  MINFOBBS
//
//  Created by juvid on 13-12-2.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "MovieLyrics.h"
#import "UIColor+expanded.h"
#import "DetectionSystemVersion.h"
#import "SBJson.h"
@interface MovieLyrics ()

@end

@implementation MovieLyrics

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([[DetectionSystemVersion alloc]Version]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    [self BackButton];
    if (self.isSelf) {
        [self GetDatas];
    }
    else{
        NSString *webviewText = @"<style>body{margin:0;background-color:transparent;color:2a2a2a;font:14px/25px Custom-Font-Name}</style>";
        webviewText = [webviewText stringByAppendingFormat:@"%@",self.strContent];
        [self.webView loadHTMLString:webviewText baseURL:nil]; //在 WebView 中显示本地的字符串
    }
    [(UIScrollView *)[[self.webView subviews] objectAtIndex:0] setBounces:NO];
    
    // Do any additional setup after loading the view from its nib.
}
-(void)BackButton{
    self.navigationItem.titleView=[DetectionSystemVersion SetBarTitle:@"百事搜"];
    [self.navigationItem setHidesBackButton:YES];
    UIButton *btnBack=[[DetectionSystemVersion alloc]BackButton];
    [btnBack addTarget:self action:@selector(BackReturn:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem=backItem;
    
}
#pragma mark 导航栏按钮事件
-(void)BackReturn:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [tRequest clearDelegatesAndCancel];
    [tRequest cancel];
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [NSThread cancelPreviousPerformRequestsWithTarget:self];
}
#pragma mark 异步数据请求
-(void)GetDatas{
       tRequest=[[[ScreenAccess alloc]init]ASIGetSearch:self.strContent Start:0 Limit:5];
    [tRequest setDelegate:self];
    [tRequest setUsername:@"allMessage"];
    
}
-(void)requestFinished:(ASIHTTPRequest*)request{
    
    NSString *response = [request responseString];
    SBJsonParser * parser = [[SBJsonParser alloc] init];
    NSMutableDictionary *Result = [parser objectWithString:response];
    
    if ([request.username isEqual:@"allMessage"]){
        BOOL IsSuccess=[[[Result objectForKey:@"Response"]objectForKey:@"status"]integerValue]==200?YES:NO;
        if (IsSuccess) {
            NSArray *arr=[[[[[[[[[Result objectForKey:@"Response"] objectForKey:@"Categories"] objectForKey:@"Category"] objectAtIndex:0]objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
            NSString *str=[NSString stringWithFormat:@"%@: %@<br>%@: %@",[[arr objectAtIndex:0] objectForKey:@"name"],[[arr objectAtIndex:0] objectForKey:@"text"],[[arr objectAtIndex:1] objectForKey:@"name"],[[arr objectAtIndex:1] objectForKey:@"text"]];
            
            
            NSString *webviewText = @"<style>body{margin:0;background-color:transparent;color:2a2a2a;font:14px/30px Custom-Font-Name}</style>";
            webviewText = [webviewText stringByAppendingFormat:@"%@",str];
             [self.webView loadHTMLString:webviewText baseURL:nil]; //在 WebView 中显示本地的字符串
        }
       
       
//                    [self.arrReturn addObjectsFromArray:[[[[[[Result objectForKey:@"Response"] objectForKey:@"Categories"] objectForKey:@"Category"] objectAtIndex:0]objectForKey:@"Items"] objectForKey:@"Item"]];
        
    }

    
}

-(void)requestFailed:(ASIHTTPRequest*)request{
   
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
